package com.akupilih.app;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.akupilih.app.adapter.CustomAdapter;
import com.akupilih.app.entity.E_Candidate;
import com.akupilih.app.entity.E_Janji;
import com.akupilih.app.model.DBClass;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class BiodataFragment extends Fragment {

	private FragmentActivity myContext;
	ListView listView;
	List<E_Candidate> dataList;
	ArrayList<HashMap<String, Object>> postitem;
	TextView nama, agama, ttl, alamat, status, istri, anak, biografi;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View rootView = inflater.inflate(R.layout.fragment_biodata, container,
				false);
		String id = getArguments().getString("id");
		DBClass db = new DBClass(myContext);
		dataList = db.selectCandidate(id);
		nama = (TextView) rootView.findViewById(R.id.nama);
		agama = (TextView) rootView.findViewById(R.id.agama);
		ttl = (TextView) rootView.findViewById(R.id.ttl);
		alamat = (TextView) rootView.findViewById(R.id.alamat);
		status = (TextView) rootView.findViewById(R.id.status);
		istri = (TextView) rootView.findViewById(R.id.istri);
		anak = (TextView) rootView.findViewById(R.id.anak);
		biografi = (TextView) rootView.findViewById(R.id.biografi);
		setList(dataList);
		return rootView;
	}

	private void setList(List<E_Candidate> dataList2) {
		postitem = new ArrayList<HashMap<String, Object>>();
		if (dataList2 != null) {
			for (E_Candidate e : dataList2) {
				nama.setText(e.getNama());
				agama.setText(e.getAgama());
				ttl.setText(e.getTempat_lahir() + ", " + e.getTgl_lahir());
				alamat.setText(e.getKelurahan() + " " + e.getKecamatan() + " "
						+ e.getKabupaten() + " " + e.getProvinsi());
				status.setText(e.getStatus_perkawinan());
				istri.setText(e.getNama_pasangan());
				anak.setText(e.getJumlah_anak());
				biografi.setText(Html.fromHtml(e.getBiografi()));
			}

		}

	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		myContext = (FragmentActivity) activity;

	}

}
